# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>

pkgbase=tlsh
pkgname=('tlsh' 'python-tlsh')
pkgver=4.8.2
pkgrel=2
pkgdesc='Fuzzy matching library that generates a hash value which can be used for similarity comparisons'
url='https://github.com/trendmicro/tlsh'
arch=('loong64' 'x86_64')
license=('Apache')
makedepends=('cmake' 'python' 'gcc-libs')
source=(https://github.com/trendmicro/${pkgbase}/archive/${pkgver}/${pkgbase}-${pkgver}.tar.gz)
sha256sums=('0528294fbb1fe3659db564dd0b7b1b27fc41280a8408e4f7abf7e8b27f7b1ac6')
sha512sums=('5355c7734f5356a3a7a31ccc078254835871fc0369f1889a34131a0f810735201c68f674eb18e975b6a03a32e5c284899ca9ffdc1f583e42192188c172d2aad0')

prepare() {
  cd ${pkgbase}-${pkgver}
  # remove garbage
  sed '/set(CMAKE_EXE_LINKER_FLAGS/d' -i CMakeLists.txt
  sed '/set(CMAKE_CXX_FLAGS/d' -i CMakeLists.txt
  sed 's|TLSH_SHARED_LIBRARY 0|TLSH_SHARED_LIBRARY 1|' -i src/CMakeLists.txt
}

build() {
  cd ${pkgbase}-${pkgver}
  mkdir -p build
  (cd build
    cmake .. \
      -DCMAKE_BUILD_TYPE=None \
      -DCMAKE_INSTALL_PREFIX:PATH=/usr \
      -DCMAKE_CXX_FLAGS="${CXXFLAGS} ${CPPFLAGS}"
    make
  )
  (cd bin
    cmake -E create_symlink tlsh_unittest tlsh
  )
  (cd py_ext
    python setup.py build
  )
}

check() {
  cd ${pkgbase}-${pkgver}
  (cd build
    make test
  )
  (cd Testing
    ./test.sh
  )
}

package_tlsh() {
  depends=('gcc-libs')
  provides=('libtlsh.so')
  cd ${pkgbase}-${pkgver}
  make -C build DESTDIR="${pkgdir}" install
  install -Dm 755 bin/tlsh_unittest -t "${pkgdir}/usr/bin"
  install -Dm 644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}"
}

package_python-tlsh() {
  depends=('python')
  cd ${pkgbase}-${pkgver}/py_ext
  python setup.py install -O1 --root="${pkgdir}" --skip-build
}

# vim: ts=2 sw=2 et:
